package org.anachronos.jeep.core.trace.impl;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;


@XmlType
@XmlAccessorType(XmlAccessType.FIELD)
public class Transaction extends Invocation {
	@XmlAttribute
	private TransactionStatus status = TransactionStatus.UNKNOWN;

	/**
	 * Required by JAXB!
	 */
	public Transaction() {
	}
	
	@Override
	public Transaction shallowCopy() {
		return new Transaction();
	}
	
	@Override
	public Object id() {
		return status;
	}
	
	public void setStatus(int status) {
		this.status = TransactionStatus.valueOf(status);
	}

	public TransactionStatus getStatus() {
		return status;
	}
	
	@Override
	public void accept(ModelVisitor visitor) {
		visitor.visit(this);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((status == null) ? 0 : status.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		Transaction other = (Transaction) obj;
		if (status == null) {
			if (other.status != null)
				return false;
		} else if (!status.equals(other.status))
			return false;
		return true;
	}

}
